package com.maila.calltaxi_driver.ui;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.maila.calltaxi_driver.R;
import com.maila.calltaxi_driver.utils.NullCheckUtil;
import com.maila.calltaxi_driver.utils.RegularUtils;
import com.maila.calltaxi_driver.utils.StartActivityUtils;
import com.zhy.autolayout.AutoLinearLayout;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by Administrator on 2017/7/3.
 */

public class LoginActivity extends AppCompatActivity {
    @BindView(R.id.title_login)
    TextView titleLogin;
    @BindView(R.id.et_phone)
    EditText etPhone;
    @BindView(R.id.btn_delete_phone)
    ImageView btnDeletePhone;
    @BindView(R.id.et_passwd)
    EditText etPasswd;
    @BindView(R.id.btn_delete_pwd)
    ImageView btnDeletePwd;
    @BindView(R.id.bt_login)
    Button btLogin;
    @BindView(R.id.forget_pwd)
    TextView forgetPwd;
    @BindView(R.id.bt_reg)
    TextView btReg;
    @BindView(R.id.mainlayout)
    AutoLinearLayout mainlayout;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.login_activity);
        ButterKnife.bind(this);
        etPasswd.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                if(hasFocus){
                    btnDeletePwd.setVisibility(View.VISIBLE);
                }else {
                    btnDeletePwd.setVisibility(View.GONE);
                }
            }
        });
        etPhone.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                if(hasFocus){
                    btnDeletePhone.setVisibility(View.VISIBLE);
                }else {
                    btnDeletePhone.setVisibility(View.GONE);
                }
            }
        });
    }

    @OnClick({R.id.btn_delete_phone, R.id.btn_delete_pwd, R.id.bt_login, R.id.forget_pwd, R.id.bt_reg})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.btn_delete_phone:
                etPhone.setText("");
                break;
            case R.id.btn_delete_pwd:
                etPasswd.setText("");
                break;
           case R.id.bt_login:
                if(NullCheckUtil.checkNullPoint(etPhone.getText().toString())&&NullCheckUtil.checkNullPoint(etPasswd.getText().toString())){
                    if(RegularUtils.isPhoneNumber(etPhone.getText().toString())){
                        StartActivityUtils.start(this,MainActivity.class);
                        finish();
                    }else {
                        Toast.makeText(this,"请输入正确的手机号",Toast.LENGTH_SHORT).show();
                    }

                }else {
                    Toast.makeText(this,"您没有输入完呢",Toast.LENGTH_SHORT).show();
                }
                break;
            case R.id.forget_pwd:
                StartActivityUtils.start(this,ForgetPwdActivity.class);
                break;
            case R.id.bt_reg:
                StartActivityUtils.start(this,RegisterActivity.class);
                break;
        }
    }
}
